package demo2;

public class Person implements Cloneable{
    public String name;
    public int age;

    public Money money = new Money();

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", money=" + money +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.money= (Money) this.money.clone();
        return tmp;
    }
}

class Test{
    public static void main(String[] args) throws CloneNotSupportedException{
        Person per1 = new Person("zhagnsan",10);
        Person per2 = (Person) per1.clone();

        per2.money.m = 6.6;
        System.out.println("per1:"+per1.money.m);

        System.out.println("per2:"+per2.money.m);

    }
}